﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WebChuangkou
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.WebBrowserShortcutsEnabled = true;
            webBrowser1.IsWebBrowserContextMenuEnabled = true;
            SuppressScriptErrorsOnly(webBrowser1);
            webBrowser1.Navigate(Application.StartupPath + "\\home.html");
            this.webBrowser1.ScriptErrorsSuppressed = true;
        }

        // 仅隐藏脚本错误，其他错误照样提示   

        private void SuppressScriptErrorsOnly(WebBrowser browser)
        {
            // 确信 ScriptErrorsSuppressed 设为 false.    
            browser.ScriptErrorsSuppressed = false;

            // 处理 DocumentCompleted 事件以访问 Document 对象.    
            browser.DocumentCompleted +=
                new WebBrowserDocumentCompletedEventHandler(
                    browser_DocumentCompleted);
        }

        private void browser_DocumentCompleted(object sender,
            WebBrowserDocumentCompletedEventArgs e)
        {
            ((WebBrowser)sender).Document.Window.Error +=
                new HtmlElementErrorEventHandler(Window_Error);
        }

        private void Window_Error(object sender,
            HtmlElementErrorEventArgs e)
        {
            // 忽略该错误并抑制错误对话框    
            e.Handled = true;
        }/* 何问起 hovertree.com */
    }
}
